Skip to content

Container: a reset keeps the sort pending for the children it keeps - #1836

Merged
obiot merged 2 commits into
masterfrom
container-reset-keeps-sort
Nov 2, 2026
Merged

obiot merged 2 commits into
masterfrom
container-reset-keeps-sort

Conversation

@obiot

@obiot obiot commented Nov 2, 2026

Copy link
Copy Markdown
Member

Description

Adding a child to a container appends it and queues a sort for the next tick. Container#reset() cancelled that sort (in clearChildren), then removed every child that is not persistent. The persistent children it kept therefore stayed in the order they were added, their depth ignored, until something else sorted the container.

The usual way to get there: a screen adds its persistent objects and loads a level straight away. level.load resets the world, so the screen's own objects were never sorted:

world.addChild(sky, -10);   // persistent
world.addChild(board, 0);   // persistent, the level goes in here
world.addChild(hud, 10);    // persistent
await level.load("map", { container: board, async: true });
// before: sky drawn over the board and the HUD

It showed up in the Starsweep example as a screen with nothing but the background on it. The example works around it with a world.sort() after each load.

Fix

  • reset() notes whether a sort was pending and, if any children remain after clearing, sorts again (the same deferred sort() that addChild queues).
  • destroy() is untouched. It calls clearChildren directly, so nothing is queued against a destroyed container, which is the problem the clearChildren split was made to avoid.

Also:

  • Changelog: a Fixed entry.
  • Skills: a symptom row in the Tiled skill, with the workaround for older versions.

Type of change

  • Bug fix
  • New feature
  • Documentation update
  • Performance improvement
  • Refactoring (no functional changes)

Checklist

  • I have read the Contributing Guide
  • My code follows the existing code style (pnpm lint passes): Biome and tsc clean, no new ESLint warnings
  • I have tested my changes locally (pnpm test passes): full engine suite, 379 files / 9624 tests pass
  • I have added tests that cover my changes (if applicable): tests/container-reset-sort.spec.js. The reset() case and the level.load case fail without the fix (sky on top) and pass with it. Three more pin that no sort is queued when none was pending, when no children remain, or on destroy().
  • The build succeeds (pnpm build): left to CI

Related issues

None.


Generated by Claude Code

Adding a child queues a sort for the next tick. Container#reset cancelled
that sort, then removed every child that is not persistent, so the
persistent ones it kept stayed in the order they were added, their depth
ignored, until something else sorted the container. A screen that adds its
persistent objects and loads a level straight away got exactly that, since
level.load resets the world: a background added first was drawn over
everything.

reset() now sorts again when a sort was pending and children remain.
destroy() does not: it goes through clearChildren alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JnzwA2BZwXkRJLpNxCXBNt
Copilot AI balanced review requested due to automatic review settings November 2, 2026 09:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JnzwA4xBNBw7cEZzG1bUru
Copilot AI balanced review requested due to automatic review settings November 2, 2026 10:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@obiot
obiot merged commit e1b7a8e into master Nov 2, 2026
6 checks passed
@obiot
obiot deleted the container-reset-keeps-sort branch November 2, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants